package com.wiscamp.ninechapters.challenges.infrastructure.mappers;

import com.wiscamp.ninechapters.challenges.infrastructure.po.GroupUserPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

@Repository
public interface ChallengeGroupUserMapper extends JpaRepository<GroupUserPO, Long>, JpaSpecificationExecutor<GroupUserPO> {

    /**
     * 通过组队编号获取组队成员关联列表
     *
     * @param groupId
     * @return
     */

    @Query(value = "select e from GroupUserPO e where e.groupId = :groupId")
    Collection<GroupUserPO> getGroupUsers(long groupId);

    /**
     * 通过用户编号获取组队中第一名成员关联
     *
     * @param userId
     * @return
     */

    GroupUserPO findFirstByUserId(long userId);
}